<template>
  <div>
    <el-form :model="ruleForm" width="100px">
     <el-form-item label="账号" prop="username">
      <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
     </el-form-item>
     <el-form-item label="密码" prop="password">
      <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
     </el-form-item>
     <el-form-item>
      <el-button @click="submit">提交按钮</el-button>
     </el-form-item>
    </el-form>
  </div>
</template>
<script>
import axios from 'axios'
import { postLogin } from '@/api/api'
export default {
  data() {
    return {
      ruleForm: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    async submit() {
      // postLogin
      // let data = await axios.post('http://localhost:3000/users/login', {
      //   username: this.ruleForm.username,
      //   password: this.ruleForm.password
      // })
      let data = await postLogin({
        username: this.ruleForm.username,
        password: this.ruleForm.password
      })
      if (data.code === 0) {
        console.log(data.token, 'data') 
        sessionStorage.setItem('token', data.token)
        this.$router.push('/page')
      }
    }
  },
}
</script>